import re

def pure_ipynb2py(ipynb):
    '''Output the content in the cell without adding anything, e.g., "In[1]", in the py file'''
    py = re.split('\.',ipynb)[0]+'.py' 
    begin_python_lines = False
    with open(ipynb,'r', encoding='utf-8') as in_file, open(py, 'w',encoding='utf-8') as out_file:
        for line in in_file:
            line = line.strip()
            if line.startswith("]"):begin_python_lines = False
            if begin_python_lines:
                line = line.strip()
                line = re.sub(r'^"', '', line)
                line = re.sub(r'"$', '', line)
                line = re.sub(r'\\n",$', '', line) #正则表达式带r前缀时：只有\需要被转义，其它原样出现 
                line = re.sub(r'\\"', r'"', line)
                line = re.sub(r'\\\\',r'\\',line)# 两条反斜线降为一条
                out_file.writelines(line+"\n")
            if re.search('\"source\": \[$',line):begin_python_lines = True